import { _decorator, Node, UITransform, Vec3 } from 'cc';
import { LayerType } from '../../Basic/Config/BaseEnum';
import { PanelBase } from '../../Basic/UI/PanelBase';
import { autoComp } from '../../Basic/Manager/BaseManager';
import { Task } from '../../Util/CustomTask';

const { ccclass, property } = _decorator;
@ccclass('GuidePanel')
export class GuidePanel extends PanelBase {
  panelLayer: LayerType.TipsLayer = LayerType.TipsLayer;
  clickBackClose: boolean = false;
  blackMask: number = 0;

  @autoComp(UITransform)
  guide_finger: UITransform;

  data: {
    guideNode: Node;
    guidePos: Vec3;
    guideHandler: Task.next;
  };

  onReady(): void {
    this.refreshUI();
  }

  refreshUI() {
    this.guide_finger.node.setPosition(this.data.guidePos);
    const scale = this.data.guideNode.getWorldScale();
    const trans = this.data.guideNode.getComponent(UITransform);
    this.guide_finger.width = trans.width * scale.x;
    this.guide_finger.height = trans.height * scale.y;
  }

  onCloseReady(): void {}

  onClickBtn() {
    this.clickClose();
    this.data.guideHandler && this.data.guideHandler();
  }
}
